package com.exonline.back.controller.pay;

import com.exonline.commons.utils.TokenUtils;
import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @desc 支付宝沙箱支付接口
 * @author hbrj
 */
@WebServlet("/admin/pay")
public class PayServlet extends HttpServlet {
    ObjectMapper mapper = new ObjectMapper();
    PayService payService = new PayService();
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String method = "";
        if ( req.getParameter("method")!=null){
             method = req.getParameter("method");
        }
                try {
                if ("listpay".equals(method)) {
                    this.listpay(req, resp);
                }else {
                    this.doPay(req, resp);
                }
                } catch (Exception e) {
                    throw new ServletException(e);
                }
    }
    /**
     * @desc 1.进行支付
     * @author hbrj
     */
    private void doPay(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        payService.doPay(req, resp);
    }

    /**
     * @desc 2.进行批量购买
     * @author hbrj
     */
    private void listpay(HttpServletRequest req, HttpServletResponse resp) {
        String info = req.getParameter("info");
        String cid = TokenUtils.getCid(info);
        String sid = TokenUtils.getSid(info);
    }
}
